<?php
require_once 'to/Audio.php';

class AudiosDAO {
    const SEL_AUDIO_BY_ID = "SELECT * FROM audios WHERE status='A' AND id = %d";

    public static function getAudioById($id){
        $sSql = self::SEL_AUDIO_BY_ID;

        $DB = DBFunctions::getInstance();
        $arrNotas = $DB->execSelect($sSql, array($id));

        return self::populate($arrNotas);
    }

    private static function populate($arrAudios){

        $objAudios = array();

        foreach($arrAudios as $A){
            $objAudio = new Audio();
            $objAudio->setID($A["id"]);
            $objAudio->setTitulo($A["titulo"]);
            $objAudio->setLinkText($A["link_text"]);
            $objAudio->setFechaPublicacion($A["fecha_publicacion"]);
            $objAudio->setStatus($A["status"]);

            array_push($objAudios, $objAudio);
        }
        return $objAudios;
    }
}